import Vue from 'vue';
//导入路由插件
import Router from "vue-router";

import Test from "../views/Test";
import Home from "../views/Home";
import Main from "../components/Main";

//安装路由
Vue.use(Router);

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = Router.prototype.push;
const originalReplace = Router.prototype.replace;
//push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};

//1.创建路由组件
//2.将路由与租组件映射
//3.创建router实例
const routes=[
  {
    path:"/",
    component:Main,
    name: "Main",
    redirect: "/home",  //重定向
    children:[
      {
        path:"/home",
        component:Home,
        name: "Home"
      },{
        path:"/test",
        component:Test,
        name: "Test"
      }
    ]
  }
];
const router=new Router({
  // mode:'history',
  routes  //缩写 相当于routes:routes
});

export default router;















